import React from 'react';


const FancyButton = React.forwardRef((props, ref) => (
    <button ref={ref} className="FancyButton" onClick={props.onClick} >
        {props.children}
    </button>
));



class App extends React.Component {
    constructor(props) {
        super(props);
        this.state = {};
        this.ref;
    }

    clickHandler = () => {
        console.log(this.ref.current, "=======this.ref.current=========");
    }

    render() {
        // 你可以直接获取 DOM button 的 ref：
        const ref = React.createRef();
        this.ref = ref;
        return (
            <FancyButton ref={ref} onClick={this.clickHandler}>Click me!</FancyButton>
        );
    }
}

//尽管报错 但还显示
export default App;

//如果直接返回则页面报错不显示
// export default ErrorDemo;